﻿using JTActiveSafety.Gateway.Abstractions;
using JTActiveSafety.Gateway.Sessions;
using JTActiveSafety.Hls;
using JTActiveSafety.Protocol;
using Microsoft.Extensions.Hosting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace JTActiveSafety.Gateway.TestNormalHosting.Services
{
    public class JTActiveSafetyHlsNormalMsgHostedService : BackgroundService
    {
        //private IJTActiveSafetyMsgConsumer MsgConsumer;
        //private JTActiveSafetyHttpSessionManager HttpSessionManager;
        //private  M3U8FileManage M3U8FileManage;
        //public JTActiveSafetyHlsNormalMsgHostedService(
        //    M3U8FileManage M3U8FileManage,
        //    JTActiveSafetyHttpSessionManager httpSessionManager,
        //    IJTActiveSafetyMsgConsumer msgConsumer)
        //{
        //    MsgConsumer = msgConsumer;
        //    HttpSessionManager = httpSessionManager;
        //    this.M3U8FileManage = M3U8FileManage;
        //}
        //protected override Task ExecuteAsync(CancellationToken stoppingToken)
        //{
        //    MsgConsumer.OnMessage((Message) =>
        //    {
        //        JTActiveSafetyPackage package = JTActiveSafetySerializer.Deserialize(Message.Data);
        //        var merge = JTActiveSafety.Protocol.JTActiveSafetySerializer.Merge(package);
        //        if (merge != null)
        //        {
        //            var hasHttpSessionn = HttpSessionManager.GetAllHttpContextBySimAndChannelNo(merge.SIM, merge.LogicChannelNumber);
        //            if (hasHttpSessionn.Count>0)
        //            {
        //                M3U8FileManage.CreateTsData(merge);
        //            }
        //            else {
        //                M3U8FileManage.Clear(merge.SIM, merge.LogicChannelNumber);
        //            }
        //        }
        //    });
        //    return Task.CompletedTask;
        //}
    }
}